<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>CSS - 布局挑战</title>
    <style>
      * {
        padding: 0;
        margin: 0;
        box-sizing: border-box;
      }
      .container {
        margin-bottom: 12px;
      }

      .header {
        background-color: aliceblue;
        height: 64px;
      }

      .footer {
        background-color: bisque;
        height: 80px;
        clear: both;
      }
      .middle {
        width: 100%;
        height: 100px;
        background-color: pink;
        float: left;
      }

      .aside-left,
      .aside-right {
        float: left;
        width: 200px;
        height: 100px;
        background-color: aquamarine;
      }
      .aside-left {
        margin-left: -100%;
      }
      .aside-right {
        margin-left: -200px;
      }
      .main {
        margin-left: 200px;
        margin-right: 200px;
      }
      .middle2 {
        padding: 0 200px;
      }
      .main2 {
        width: 100%;
        height: 100px;
        background-color: pink;
        float: left;
      }
      .aside-left2,
      .aside-right2 {
        position: relative;
        width: 200px;
        height: 100px;
        background-color: aquamarine;
        float: left;
      }
      .aside-left2 {
        left: -200px;
        margin-left: -100%;
      }
      .aside-right2 {
        right: -200px;
        margin-left: -200px;
      }

      .relative-container {
        position: relative;
        width: 100px;
        height: 100px;
        background-color: bisque;
      }
      .absolute-item {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 50px;
        height: 50px;
        background-color: aqua;
        /* margin-top: -25px; */
        /* margin-left: -25px; */
        transform: translate(-50%, -50%);
      }
      .flex-container {
        display: flex;
        /* align-items: center;
        justify-content: center; */
        width: 100px;
        height: 100px;
        background-color: bisque;
      }
      .flex-item {
        width: 50px;
        height: 50px;
        margin: auto;
        background-color: aqua;
      }
      .grid-container {
        display: grid;
        place-items: center;
        width: 100px;
        height: 100px;
        background-color: bisque;
      }
      .grid-item {
        width: 50px;
        height: 50px;
        background-color: aqua;
      }

      .table-container {
        display: table;
        width: 100px;
        height: 100px;
        background-color: bisque;
      }
      .table-item {
        display: table-cell;
        text-align: center; /* 水平居中 */
        vertical-align: middle; /* 垂直居中 */
        background-color: aqua;
      }

      .text-container {
        width: 100px;
        line-height: 100px; /* 等于容器高度 */
        text-align: center;
        background-color: bisque;
      }
      .text-item {
        display: inline-block;
        vertical-align: middle;
        line-height: normal; /* 重置文本行高 */
        background-color: aqua;
      }
    </style>
  </head>
  <body>
    <!-- 实现双飞翼布局（Header, Footer, 固定左右边栏+流动主内容区） -->
    <div class="container">
      <div class="header">Header</div>
      <div class="middle">
        <div class="main">Main</div>
      </div>
      <div class="aside-left">Left</div>
      <div class="aside-right">Right</div>
      <div class="footer">Footer</div>
    </div>

    <!-- 实现圣杯布局  Header, Footer, 固定左右边栏+流动主内容区） -->
    <div class="container">
      <div class="header">Header</div>
      <div class="middle2">
        <div class="main2">Main</div>
        <div class="aside-left2">Left</div>
        <div class="aside-right2">Right</div>
      </div>
      <div class="footer">Footer</div>
    </div>

    <!-- 使用position定位实现水平垂直居中 -->
    <div class="relative-container">
      <div class="absolute-item"></div>
    </div>

    <!-- 使用flex布局实现水平垂直居中 -->
    <div class="flex-container">
      <div class="flex-item"></div>
    </div>

    <!-- 使用grid布局实现水平垂直居中 -->
    <div class="grid-container">
      <div class="grid-item"></div>
    </div>

    <!-- 使用表格布局实现水平垂直居中 -->
    <div class="table-container">
      <!-- 表格单元格会根据父表格单元的尺寸自动扩展。即使设置子元素的宽高，它仍然会尝试填满父容器的 100px 的高度和宽度。 -->
      <div class="table-item">222</div>
    </div>

    <!-- 特殊场景 line-height-->
    <div class="text-container">
      <div class="text-item">居中文本</div>
    </div>
  </body>
</html>
